<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" placeholder="请输入年份" class="y1" />
    <input type="text" placeholder="请输入月份" class="m1" />
    <button>查询天数</button>
  </body>
</html>
<script>
  var year = document.querySelector(".y1");
  var month = document.querySelector(".m1");
  var btn = document.querySelector("button");
  btn.onclick = function () {
    if (year.value.trim() == "") return alert("请输入内容");
    if (month.value.trim() == "") return alert("请输入内容");
    if (isNaN(year.value)) return alert("请输入数字");
    if (isNaN(month.value)) return alert("请输入数字");
    if (
      year.value / 400 == "0" ||
      (year.value % 4 == "0" && year.value % 100 !== "0")
    ) {
      if (
        month.value == "1" ||
        month.value == "3" ||
        month.value == "5" ||
        month.value == "7" ||
        month.value == "8" ||
        month.value == "10" ||
        month.value == "12"
      ) {
        alert(month.value + "月有31天");
      } else if (
        month.value == "4" ||
        month.value == "6" ||
        month.value == "9" ||
        month.value == "11"
      ) {
        alert(month.value + "月有30天");
      } else if (month.value == "2") {
        alert(month.value + "月有29天");
      }
    } else if (
      month.value == "1" ||
      month.value == "3" ||
      month.value == "5" ||
      month.value == "7" ||
      month.value == "8" ||
      month.value == "10" ||
      month.value == "12"
    ) {
      alert(month.value + "月有31天");
    } else if (
      month.value == "4" ||
      month.value == "6" ||
      month.value == "9" ||
      month.value == "11"
    ) {
      alert(month.value + "月有30天");
    } else if (month.value == "2") {
      alert(month.value + "月有28天");
    }
  };
</script>
